using System;
using System.Data;
using System.Collections.Generic;

namespace AbstractSql {
    public class Reader {
        IDataReader reader;
        public Reader(IDataReader r) {
            if (r == null)
                throw new ArgumentNullException("r");
            reader = r;
        }
        public T Get<T>(string col) {
			return _Get<T>(reader, col);
        }
        public static T Read<T>(IDataReader r, string col) {
            return _Get<T>(r, col);
        }
		public static T Read<T>(IDataReader r, int col) {
            return _Get<T>(r, col);
        }
		static T _Get<T>(IDataReader reader, string col) {
            object dummy = reader[col];
            if (dummy == DBNull.Value)
                dummy = null;
            return (T)dummy;
        }
		static T _Get<T>(IDataReader reader, int col) {
            object dummy = reader[col];
            if (dummy == DBNull.Value)
                dummy = null;
            return (T)dummy;
        }
    }
}